<?php
if( !defined('IN_INDEX') )
{
	die('This page is hidden.');
}
if(!checkSession())
{
	function redirect($url)
			{
			?>
				<script type="text/javascript">
					{
					window.location = "<?php echo $url; ?>";
					}
				</script>
			<?php 
			}
			redirect("index.php?action=login");
	exit;
}
else
{
	if(isset($_REQUEST['id']))
	{
		$USER_PROFILE = new User('id', $_REQUEST['id']);
		$page_url = "index.php?action=profile&id=" . $_REQUEST['id'] . "&sub=stats";
	}
	else
	{
		$USER_PROFILE = $USER;
		$page_url = "index.php?action=profile&sub=stats";
	}
}
include('inc/functions_blog.php');
$blogs = getTrainingList(" WHERE user_id='" . $USER_PROFILE->getId() . "'");
$dateformat = $CONFIG['date_format'];
?>

<div id='postpath'>
		<a title="<?php echo translate('gotofrontpage'); ?>" href="index.php"><?php echo translate('home'); ?></a>
		 &gt; <a href="index.php?action=blogs" title='<?php echo translate('showallblogs'); ?>'><?php echo translate('blog'); ?></a> 
         &gt; <a href="index.php?action=profile&id=<?php echo $USER_PROFILE->getId(); ?>"><?php echo ucf($USER_PROFILE->getFirstname()) . " " . ucf($USER_PROFILE->getLastname()); ?></a>
		&gt; <a href="index.php?action=profile&sub=stats&id=<?php echo $USER_PROFILE->getId(); ?>" title='<?php echo translate('stats'); ?>'><?php echo translate('stats'); ?></a>
        &gt; <a href="index.php?action=profile&sub=stats_records&id=<?php echo $USER_PROFILE->getId(); ?>" title='<?php echo translate('records'); ?>'><?php echo translate('records'); ?></a>
</div>
<?php 

if(count($blogs) > 0)
{
?>
<br />
<h2><?php echo translate('records'); ?></h2>
<br />
<?php echo translate('records_subtext'); ?>
<br /><br />


<?php 
	// Get all the data
	$result = mysql_query("SELECT 
	lifts.kg,
	lifts.url,
	lifts.exercise_id,
	lifts.training_id,
	training.training_id,
	training.place,
	training.date,
	training.user_id,
	training.bodyweight
	FROM lifts, training
	WHERE training.user_id= ". $USER_PROFILE->getId() ." 
	ORDER BY lifts.exercise_id DESC") or die(mysql_error());

$num = mysql_num_rows($result);
$i=0;

if($i < $num)
{ 
		echo "<table border='1'>";
		echo "<tr><th>" . translate('exercise') . "</th><th>" . translate('date') . "</th><th>". ucf(translate('place')) ."</th><th>" . ucf(translate('bodyweight')) . "</th><th>". translate('lifted') ."</th></tr>";
		
		
		// keeps getting the next row until there are no more to get
		while($row = mysql_fetch_array($result)) 
		{
			// Print out the contents of each row into a table
			echo "<tr><td width='140' align='center'>";
			echo translate(getExercisename($row['exercise_id']));
			echo "<td width='140' align='center'>";
			echo formatDate($row['date'], $dateformat);
			echo "</td><td width='160' align='center'>";
			echo $row['place'];
			echo "</td><td width='100' align='center'>";
			echo r_nr2(calcFromKg($row['bodyweight'])). $w_metric;
			echo "</td><td width='130' align='center'>"; 
			echo "<a href='index.php?action=profile&sub=show&tid=". $row['training_id'] ."'>";
			if($w_metric == "kg")
			{
			echo r_nr2(calcFromKg($row['kg'])). $w_metric . "</a>";
				
				if($row['url'] != "")
				{
					echo " <a href='" . $row['url'] . "' target='_blank'><img title=". translate('show_video') ." src='img/video.png' /></a>";
				}
			}
			else
			{
			echo r_nr(calcFromKg($row['kg'])). $w_metric . "</a>";
				
				if($row['url'] != "")
				{
					echo " <a href='" . $row['url'] . "' target='_blank'><img alt=title=". translate('show_video') ." title=". translate('show_video') ." src='img/video.png' /></a>";
				}
			}
			echo "</td></tr>"; 
		}
				
		
		echo "</table><div class='fixed'>
							</div>
						</div>
						</div>
					<div class='fixed'>
					</div>
					<div id='footer'>
					<a id='gotop' href='#' onclick='MGJS.goTop();return false;'>" . translate('top') . "</a>
						<div align='center' id='copyright'>&copy; " . translate('copyrightyear') . " " . translate('header_text'). " - " .  translate('curversion') ." - <a href='index.php?action=contact'>" . translate('contact') ."</a> - <a href='index.php?action=about'>" . translate('about') . "</a> - " . translate('onlineusers'). ": " . getActiveUsers() . "<br />
						</div>";
			exit;
			
}
else
{
	echo translate('noresultshof');
	echo "<div class='fixed'>
					</div>
				</div>
				</div>
			<div class='fixed'>
			</div>
			<div id='footer'>
			<a id='gotop' href='#' onclick='MGJS.goTop();return false;'>" . translate('top') . "</a>
				<div align='center' id='copyright'>&copy; " . translate('copyrightyear') . " " . translate('header_text'). " - " .  translate('curversion') ." - <a href='index.php?action=contact'>" . translate('contact') ."</a> - <a href='index.php?action=about'>" . translate('about') . "</a> - " . translate('onlineusers'). ": " . getActiveUsers() . "<br />
                </div>";
	exit;
} 
}
else
{
  echo "<br /><br /><br /><br /><br /><br /><br /><br /><br />
		<center><h2>" . translate('addanewtrainingtostart') . "</h2></center>";
}
?>